package com.example.datn.activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.example.datn.R;

public class DoctinRssActivity extends Activity{
	private WebView webview;
	private static final String TAG = "Main";
	  private ProgressDialog progressBar;
	
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.doctinrss);
	Bundle bundle=getIntent().getExtras();
	String link=bundle.getString("LINK");
	//Toast.makeText(this, "hihi"+ link, Toast.LENGTH_LONG).show();
webview=(WebView)findViewById(R.id.webViewrss);
webview.getSettings().setJavaScriptEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

progressBar = ProgressDialog.show(DoctinRssActivity.this, "Đang tải dữ liệu", "Loading...");




webview.getSettings().setSupportZoom(true);
webview.setInitialScale(1);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.setScrollbarFadingEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(link);
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Log.i(TAG, "Processing webview url click...");
    view.loadUrl(url);
    return true;
}

public void onPageFinished(WebView view, String url) {
    Log.i(TAG, "Finished loading URL: " + url);
    if (progressBar.isShowing()) {
        progressBar.dismiss();
    }
}

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    Log.e(TAG, "Error: " + description);
    Toast.makeText(DoctinRssActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
    alertDialog.setTitle("Error");
    alertDialog.setMessage(description+". \nXem lại kết nối internet của bạn");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    alertDialog.show();
}
});



}


}
